/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/controller/selection.h"
#include "PlanetWars2dRT-core/specific/model/ship.h"


EXTERN_C_BEGIN


size_t
selection_2d_uint_move_ships_of_player_index(universe_t*              a_universe,
					     const selection_2d_uint* a_selection,
					     unsigned char            player_index,
					     const position_2d_uint*  position_to_go)
{
  ship_t** ships;
  size_t nb;
  
  ships = selection_2d_uint_get_ships_of_player_index(a_universe,
						      a_selection,
						      player_index,
						      &nb);
  if(ships == NULL)
    {
      return 0;
    }
  
  for(size_t i=0; i < nb; ++i)
    {
      ship_set_top_left_position_to_go(ships[i], position_to_go);
    }
  
  free(ships);
  return nb;
}


EXTERN_C_END
